package com.example.service;

import com.example.consts.OrderStatus;
import com.example.pojo.dao.OrdersDao;
import com.example.pojo.dao.ResumeDao;
import com.example.pojo.entity.Orders;
import com.example.pojo.entity.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ResumeServiceImpl implements ResumeService{
    @Autowired
    private ResumeDao resumeDao;
    @Autowired
    private OrdersDao ordersDao;
    @Override
    public List<Resume> selectResume() {
        List<Resume> resumeList = resumeDao.findAll();
        return resumeList;
    }

    @Override
    public List<Orders> findBuyResume(Integer jsId) {
        List<Orders> buyList1 = ordersDao.findByJsId(jsId);
        List<Orders> buyList = new ArrayList<>();
        for (Orders o : buyList1) {
            if (o.getOrdStatus().equals(OrderStatus.SUCCESS.getType())){
                buyList.add(o);
            }
        }
        return buyList;
    }

    @Override
    public String getAddressIfBuy(String name, Integer jsId) {
        System.out.println(">>>>>>>>>>>>>>>>>>>>>");
        List<Orders> ordersList = ordersDao.findByOrdTitleAndJsId(name, jsId);
        System.out.println("[[[[[[[[[[[[[[[[[[[[[[");
        String buyaddress = "";
        if (ordersList==null){
            System.out.println("]]]]]]]]]]]]]]]]]]]]");
            return null;
        }
        for (Orders o : ordersList) {
            System.out.println("????????????????????");
            if (o.getOrdStatus().equals(OrderStatus.SUCCESS.getType())){
                System.out.println("!!!!!!!!!!!!!!!");
                Integer resuId = o.getResuId();
                Resume resume = resumeDao.findById(resuId).get();
                System.out.println("////////////////////");
                buyaddress = resume.getQnaddress();
            }
        }
        System.out.println(buyaddress+"}}}}}}}");
        return buyaddress;
    }
}
